<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<script src="${pageContext.request.contextPath}/script/tools/cron.js" type="text/javascript"></script>
<script type="text/javascript">
	var form_url = base.contextPath+"/sysmgr/task/add.do" ;
	var tabsContainer, t ;
	$(function() {
		tabsContainer = $("#tabsContainer").tabs({
			fit: true, border: false
		}) ;
		t = $("#task_type").combobox({
			url: base.contextPath+"/common/sys_res/task-job-data.json",
			valueField: 'id', textField: 'task_type', panelHeight:'auto', editable:false, autoShowPanel: true,
			onSelect: function(rec){
				var task = $.array.first(t.combobox('getData'), function (val) { return val.id == rec.id; });
				$("input[name=task_job_class]").val(task.task_job_class);
				$("input[name=task_type_name]").val(rec.task_type);
			}
		});
		$("#task_enable").combobox({
			valueField: 'label', textField: 'value', value: 'Y',
			data: [{ label: 'Y', value: '启动' },{ label: 'N', value: '停止' }],
			panelHeight:'auto', editable:false, autoShowPanel: true,
		});
		
		//编辑，加载表单数据
		if($('input[name=id]').val().length > 0) {
			form_url = base.contextPath+"/sysmgr/task/edit.do" ;
			$.post(base.contextPath+"/sysmgr/task/get.do", {id:$('input[name=id]').val()}, function(result) {
				if (result.id != undefined) {
					$('form').form('load', {
						'id' : result.id,
						'task_name' : result.task_name,
						'task_enable' : result.task_enable,
						'task_remark' : result.task_remark,
						'task_code' : result.task_code,
						'task_type' : result.task_type,
						'cron_expression' : result.cron_expression,
						'task_type_name' : result.task_type_name,
						'task_job_class' : result.task_job_class
					});
				}
			}, 'json').error(function(){$.easyui.loaded();});
		} 
	});
	
	//提交表单数据
	var submitNow = function($d, $dg, flag) {
		var o = $("#form").form("getData") ;
		o["cron_expression"] = $("input[name=cron_expression]").val();
		
		$.post(form_url, o, function(result) {
			if (result.status) {
				$dg.datagrid('reload');alertify.success(result.msg);$.easyui.loaded();
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();$.messager.alert("错误", result.msg, "error");
			}
		}, 'json').error(function(){$.easyui.loaded();});
	};
	
	//验证表单
	var submitForm = function($d, $dg, flag) { 
		if($('#form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			submitNow($d, $dg, flag) ;
		}
	};
</script>

<div class="easyui-layout" data-options="fit: true">
	<div data-options="region: 'north', border: false" style="height:95px;">
	
		<form id="form" class="easyui-form form_container">
			<input type="hidden" name="id" value="${id}" />
			<input type="hidden" name="modifyName" value="${USER_SESSION.truename}" />
			<input type="hidden" name="task_code" />
			<input type="hidden" name="task_type_name" />
			<input type="hidden" name="task_job_class" />
			<table class="tableform">
				<tr>
					<th>任务名称：</th>
					<td><input name="task_name" class="easyui-validatebox" type="text" data-options="required: true,prompt: '任务名称'" /></td>
					<th>任务类型：</th>
					<td><input id="task_type" name="task_type" style="width:218px;height:30px;" /></td>
				</tr>
				<tr>
					<th>任务状态：</th>
					<td><input id="task_enable" name="task_enable" style="width:218px;height:30px;" /></td>
					<th>任务备注：</th>
					<td><input name="task_remark" class="easyui-validatebox" type="text" data-options="prompt: '任务备注'" /></td>
				</tr>
			</table>
		</form>
		
	</div>
	<div data-options="region: 'center', border: true" style="border-left: 0px; border-right: 0px;">
	 	<div id="tabsContainer">
			<div data-options="title: '秒', refreshable: false,selected:true">
				<div class="line"><input type="radio" checked="checked" name="second" onclick="everyTime(this)"> 每秒 允许的通配符[, - * /]</div>
				<div class="line"><input type="radio" name="second" onclick="cycle(this)"> 周期从 <input class="numberspinner" style="width:60px;" data-options="min:1,max:58" value="1"> - <input class="numberspinner" style="width:60px;" data-options="min:2,max:59" value="2"> 秒</div>
				<div class="line"><input type="radio" name="second" onclick="startOn(this)"> 从 <input class="numberspinner" style="width:60px;" data-options="min:0,max:59" value="0"> 秒开始,每 <input class="numberspinner" style="width:60px;" data-options="min:1,max:59" value="1"> 秒执行一次</div>
				<div class="line"><input type="radio" name="second" id="sencond_appoint"> 指定</div>
				<div class="imp secondList">
					<input type="checkbox" value="1">01
					<input type="checkbox" value="2">02
					<input type="checkbox" value="3">03
					<input type="checkbox" value="4">04
					<input type="checkbox" value="5">05
					<input type="checkbox" value="6">06
					<input type="checkbox" value="7">07
					<input type="checkbox" value="8">08
					<input type="checkbox" value="9">09
					<input type="checkbox" value="10">10</div><div class="imp secondList">
					<input type="checkbox" value="11">11
					<input type="checkbox" value="12">12
					<input type="checkbox" value="13">13
					<input type="checkbox" value="14">14
					<input type="checkbox" value="15">15
					<input type="checkbox" value="16">16
					<input type="checkbox" value="17">17
					<input type="checkbox" value="18">18
					<input type="checkbox" value="19">19
					<input type="checkbox" value="20">20</div><div class="imp secondList">
					<input type="checkbox" value="21">21
					<input type="checkbox" value="22">22
					<input type="checkbox" value="23">23
					<input type="checkbox" value="24">24
					<input type="checkbox" value="25">25
					<input type="checkbox" value="26">26
					<input type="checkbox" value="27">27
					<input type="checkbox" value="28">28
					<input type="checkbox" value="29">29
					<input type="checkbox" value="30">30</div><div class="imp secondList">
					<input type="checkbox" value="31">31
					<input type="checkbox" value="32">32
					<input type="checkbox" value="33">33
					<input type="checkbox" value="34">34
					<input type="checkbox" value="35">35
					<input type="checkbox" value="36">36
					<input type="checkbox" value="37">37
					<input type="checkbox" value="38">38
					<input type="checkbox" value="39">39
					<input type="checkbox" value="40">40</div><div class="imp secondList">
					<input type="checkbox" value="41">41
					<input type="checkbox" value="42">42
					<input type="checkbox" value="43">43
					<input type="checkbox" value="44">44
					<input type="checkbox" value="45">45
					<input type="checkbox" value="46">46
					<input type="checkbox" value="47">47
					<input type="checkbox" value="48">48
					<input type="checkbox" value="49">49
					<input type="checkbox" value="50">50</div><div class="imp secondList">
					<input type="checkbox" value="51">51
					<input type="checkbox" value="52">52
					<input type="checkbox" value="53">53
					<input type="checkbox" value="54">54
					<input type="checkbox" value="55">55
					<input type="checkbox" value="56">56
					<input type="checkbox" value="57">57
					<input type="checkbox" value="58">58
					<input type="checkbox" value="59">59
				</div>
			</div>
			<div data-options="title: '分', refreshable: false">
				<div class="line"><input type="radio" checked="checked" name="min" onclick="everyTime(this)"> 分钟 允许的通配符[, - * /]</div>
				<div class="line"><input type="radio" name="min" onclick="cycle(this)"> 周期从 <input class="numberspinner" style="width:60px;" data-options="min:1,max:58" value="1"> - <input class="numberspinner" style="width:60px;" data-options="min:2,max:59" value="2"> 分钟</div>
				<div class="line"><input type="radio" name="min" onclick="startOn(this)"> 从 <input class="numberspinner" style="width:60px;" data-options="min:0,max:59" value="0"> 分钟开始,每 <input class="numberspinner" style="width:60px;" data-options="min:1,max:59" value="1"> 分钟执行一次</div>
				<div class="line"><input type="radio" name="min" id="min_appoint"> 指定</div>
				<div class="imp minList">
					<input type="checkbox" value="1">01
					<input type="checkbox" value="2">02
					<input type="checkbox" value="3">03
					<input type="checkbox" value="4">04
					<input type="checkbox" value="5">05
					<input type="checkbox" value="6">06
					<input type="checkbox" value="7">07
					<input type="checkbox" value="8">08
					<input type="checkbox" value="9">09
					<input type="checkbox" value="10">10</div><div class="imp minList">
					<input type="checkbox" value="11">11
					<input type="checkbox" value="12">12
					<input type="checkbox" value="13">13
					<input type="checkbox" value="14">14
					<input type="checkbox" value="15">15
					<input type="checkbox" value="16">16
					<input type="checkbox" value="17">17
					<input type="checkbox" value="18">18
					<input type="checkbox" value="19">19
					<input type="checkbox" value="20">20</div><div class="imp minList">
					<input type="checkbox" value="21">21
					<input type="checkbox" value="22">22
					<input type="checkbox" value="23">23
					<input type="checkbox" value="24">24
					<input type="checkbox" value="25">25
					<input type="checkbox" value="26">26
					<input type="checkbox" value="27">27
					<input type="checkbox" value="28">28
					<input type="checkbox" value="29">29
					<input type="checkbox" value="30">30</div><div class="imp minList">
					<input type="checkbox" value="31">31
					<input type="checkbox" value="32">32
					<input type="checkbox" value="33">33
					<input type="checkbox" value="34">34
					<input type="checkbox" value="35">35
					<input type="checkbox" value="36">36
					<input type="checkbox" value="37">37
					<input type="checkbox" value="38">38
					<input type="checkbox" value="39">39
					<input type="checkbox" value="40">40</div><div class="imp minList">
					<input type="checkbox" value="41">41
					<input type="checkbox" value="42">42
					<input type="checkbox" value="43">43
					<input type="checkbox" value="44">44
					<input type="checkbox" value="45">45
					<input type="checkbox" value="46">46
					<input type="checkbox" value="47">47
					<input type="checkbox" value="48">48
					<input type="checkbox" value="49">49
					<input type="checkbox" value="50">50</div><div class="imp minList">
					<input type="checkbox" value="51">51
					<input type="checkbox" value="52">52
					<input type="checkbox" value="53">53
					<input type="checkbox" value="54">54
					<input type="checkbox" value="55">55
					<input type="checkbox" value="56">56
					<input type="checkbox" value="57">57
					<input type="checkbox" value="58">58
					<input type="checkbox" value="59">59
				</div>
			</div>
			<div data-options="title: '小时', refreshable: false">
				<div class="line"><input type="radio" checked="checked" name="hour" onclick="everyTime(this)"> 小时 允许的通配符[, - * /]</div>
				<div class="line"><input type="radio" name="hour" onclick="cycle(this)"> 周期从 <input class="numberspinner" style="width:60px;" data-options="min:0,max:23" value="0"> - <input class="numberspinner" style="width:60px;" data-options="min:2,max:23" value="2"> 小时</div>
				<div class="line"><input type="radio" name="hour" onclick="startOn(this)"> 从 <input class="numberspinner" style="width:60px;" data-options="min:0,max:23" value="0"> 小时开始,每 <input class="numberspinner" style="width:60px;" data-options="min:1,max:23" value="1"> 小时执行一次</div>
				<div class="line"><input type="radio" name="hour" id="hour_appoint"> 指定</div>
				<div class="imp hourList">AM:
					<input type="checkbox" value="0">00
					<input type="checkbox" value="1">01
					<input type="checkbox" value="2">02
					<input type="checkbox" value="3">03
					<input type="checkbox" value="4">04
					<input type="checkbox" value="5">05
					<input type="checkbox" value="6">06
					<input type="checkbox" value="7">07
					<input type="checkbox" value="8">08
					<input type="checkbox" value="9">09
					<input type="checkbox" value="10">10
					<input type="checkbox" value="11">11
				</div>
				<div class="imp hourList">PM:
					<input type="checkbox" value="12">12
					<input type="checkbox" value="13">13
					<input type="checkbox" value="14">14
					<input type="checkbox" value="15">15
					<input type="checkbox" value="16">16
					<input type="checkbox" value="17">17
					<input type="checkbox" value="18">18
					<input type="checkbox" value="19">19
					<input type="checkbox" value="20">20
					<input type="checkbox" value="21">21
					<input type="checkbox" value="22">22
					<input type="checkbox" value="23">23
				</div>
			</div>
			<div data-options="title: '日', refreshable: false">
				<div class="line"><input type="radio" checked="checked" name="day" onclick="everyTime(this)"> 日 允许的通配符[, - * / L W]</div>
				<div class="line"><input type="radio" name="day" onclick="unAppoint(this)"> 不指定</div>
				<div class="line"><input type="radio" name="day" onclick="cycle(this)"> 周期从 <input class="numberspinner" style="width:60px;" data-options="min:1,max:31" value="1"> - <input class="numberspinner" style="width:60px;" data-options="min:2,max:31" value="2"> 日</div>
				<div class="line"><input type="radio" name="day" onclick="startOn(this)"> 从 <input class="numberspinner" style="width:60px;" data-options="min:1,max:31" value="1"> 日开始,每 <input class="numberspinner" style="width:60px;" data-options="min:1,max:31" value="1"> 天执行一次</div>
				<div class="line"><input type="radio" name="day" onclick="workDay(this)"> 每月 <input class="numberspinner" style="width:60px;" data-options="min:1,max:31" value="1"> 号最近的那个工作日</div>
				<div class="line"><input type="radio" name="day" onclick="lastDay(this)"> 本月最后一天</div>
				<div class="line"><input type="radio" name="day" id="day_appoint"> 指定</div>
				<div class="imp dayList">
					<input type="checkbox" value="1">01
					<input type="checkbox" value="2">02
					<input type="checkbox" value="3">03
					<input type="checkbox" value="4">04
					<input type="checkbox" value="5">05
					<input type="checkbox" value="6">06
					<input type="checkbox" value="7">07
					<input type="checkbox" value="8">08
					<input type="checkbox" value="9">09
					<input type="checkbox" value="10">10
					<input type="checkbox" value="11">11
					<input type="checkbox" value="12">12
					<input type="checkbox" value="13">13
					<input type="checkbox" value="14">14
					<input type="checkbox" value="15">15
					<input type="checkbox" value="16">16
				</div>
				<div class="imp dayList">
					<input type="checkbox" value="17">17
					<input type="checkbox" value="18">18
					<input type="checkbox" value="19">19
					<input type="checkbox" value="20">20
					<input type="checkbox" value="21">21
					<input type="checkbox" value="22">22
					<input type="checkbox" value="23">23
					<input type="checkbox" value="24">24
					<input type="checkbox" value="25">25
					<input type="checkbox" value="26">26
					<input type="checkbox" value="27">27
					<input type="checkbox" value="28">28
					<input type="checkbox" value="29">29
					<input type="checkbox" value="30">30
					<input type="checkbox" value="31">31
				</div>
			</div>
			<div data-options="title: '月', refreshable: false">
				<div class="line"><input type="radio" checked="checked" name="mouth" onclick="everyTime(this)"> 月 允许的通配符[, - * /]</div>
				<div class="line"><input type="radio" name="mouth" onclick="unAppoint(this)"> 不指定</div>
				<div class="line"><input type="radio" name="mouth" onclick="cycle(this)"> 周期从 <input class="numberspinner" style="width:60px;" data-options="min:1,max:12" value="1"> - <input class="numberspinner" style="width:60px;" data-options="min:2,max:12" value="2"> 月</div>
				<div class="line"><input type="radio" name="mouth" onclick="startOn(this)"> 从 <input class="numberspinner" style="width:60px;" data-options="min:1,max:12" value="1"> 日开始,每 <input class="numberspinner" style="width:60px;" data-options="min:1,max:12" value="1"> 月执行一次</div>
				<div class="line"><input type="radio" name="mouth" id="mouth_appoint"> 指定</div>
				<div class="imp mouthList">
					<input type="checkbox" value="1">1
					<input type="checkbox" value="2">2
					<input type="checkbox" value="3">3
					<input type="checkbox" value="4">4
					<input type="checkbox" value="5">5
					<input type="checkbox" value="6">6
					<input type="checkbox" value="7">7
					<input type="checkbox" value="8">8
					<input type="checkbox" value="9">9
					<input type="checkbox" value="10">10
					<input type="checkbox" value="11">11
					<input type="checkbox" value="12">12
				</div>
			</div>
			<div data-options="title: '周', refreshable: false">
				<div class="line"><input type="radio" checked="checked" name="week" onclick="everyTime(this)"> 周 允许的通配符[, - * / L #]</div>
				<div class="line"><input type="radio" name="week" onclick="unAppoint(this)"> 不指定</div>
				<div class="line"><input type="radio" name="week" onclick="startOn(this)"> 周期 从星期<input class="numberspinner" style="width:60px;" data-options="min:1,max:7" value="1"> - <input class="numberspinner" style="width:60px;" data-options="min:2,max:7" value="2"></div>
				<div class="line"><input type="radio" name="week" onclick="weekOfDay(this)"> 第<input class="numberspinner" style="width:60px;" data-options="min:1,max:4" value="1"> 周 的星期<input class="numberspinner" style="width:60px;" data-options="min:1,max:7" value="1"></div>
				<div class="line"><input type="radio" name="week" onclick="lastWeek(this)"> 本月最后一个星期<input class="numberspinner" style="width:60px;" data-options="min:1,max:7" value="1"></div>
				<div class="line"><input type="radio" name="week" id="week_appoint"> 指定</div>
				<div class="imp weekList">
					<input type="checkbox" value="1">1
					<input type="checkbox" value="2">2
					<input type="checkbox" value="3">3
					<input type="checkbox" value="4">4
					<input type="checkbox" value="5">5
					<input type="checkbox" value="6">6
					<input type="checkbox" value="7">7
				</div>
			</div>
			<div data-options="title: '年', refreshable: false">
				<div class="line"><input type="radio" checked="checked" name="year" onclick="unAppoint(this)"> 不指定 允许的通配符[, - * /] 非必填</div>
				<div class="line"><input type="radio" name="year" onclick="everyTime(this)"> 每年</div>
				<div class="line"><input type="radio" name="year" onclick="cycle(this)">周期 从 <input class="numberspinner" style="width:90px;" data-options="min:2013,max:3000" value="2013"> - <input class="numberspinner" style="width:90px;" data-options="min:2014,max:3000" value="2014"></div>
			</div>
		</div>
	</div>
	<div data-options="region: 'south', border: false" style="height:110px;">
		<table class="cron_view">
			<tbody>
				<tr>
					<th align="center"></th>
					<th align="center">秒</th>
					<th align="center">分钟</th>
					<th align="center">小时</th>
					<th align="center">日</th>
					<th align="center">月</th>
					<th align="center">星期</th>
					<th align="center">年</th>
				</tr>
				<tr>
					<td></td>
					<td><input type="text" style="width:100px;" name="v_second" class="col" value="*" readonly="readonly"/></td>
					<td><input type="text" style="width:100px;" name="v_min" class="col" value="*" readonly="readonly"/></td>
					<td><input type="text" style="width:100px;" name="v_hour" class="col" value="*" readonly="readonly"/></td>
					<td><input type="text" style="width:100px;" name="v_day" class="col" value="*" readonly="readonly"/></td>
					<td><input type="text" style="width:100px;" name="v_mouth" class="col" value="*" readonly="readonly"/></td>
					<td><input type="text" style="width:100px;" name="v_week" class="col" value="?" readonly="readonly"/></td>
					<td><input type="text" style="width:100px;" name="v_year"  class="col" readonly="readonly"/></td>
				</tr>
				<tr>
					<td>Cron表达式:</td>
					<td colspan="7"><input type="text" name="cron_expression" style="width:99.9%;" value="* * * * * ? " id="cron" readonly="readonly"/></td>
				</tr>
			</tbody>
		</table>
	</div>
</div>
